package etxt2db.corpus;

import java.util.List;

import org.apache.uima.jcas.tcas.Annotation;

/**
 * A generic type of annotation, supposed to wrap any UIMA annotation. 
 * Contains the index of the beginning and ending of a classified span, 
 * as well as the text it covers, the specific type of the annotation wrapped
 * and a list of objects identifying this particular annotation.
 * <p>
 * @author Rui Lageira
 *
 */
public class MyAnnotation {

	private int begin;
	private int end;
	private String type;
	private String coveredText;
	
	private List<Object> distinguisher;
	
	/**
	 * Constructs a new annotation wrapper from a generic UIMA annotation, capturing
	 * his beginning and ending indexes, his covered text. Also saves the specific type 
	 * and the list of objects identifying that particular annotation.
	 * <p>
	 * @param annotation	the UIMA annotation to wrap
	 * @param type			the specific type of the annotation, 
	 * 						as in a keyword mapping to the actual 
	 * 						class name, according to the file 
	 * 						<code>config/type_mappings.config</code>
	 * @param distinguisher	the list of Objects identifying a particular annotation
	 */
	public MyAnnotation(Annotation annotation, String type, List<Object> distinguisher) {
		setBegin(annotation.getBegin());
		setEnd(annotation.getEnd());
		setCoveredText(annotation.getCoveredText());
		setType(type);
		setDistinguisher(distinguisher);
	}

	/**
	 * @return the index of the beginning of the text classified from a document
	 */
	public int getBegin() {
		return begin;
	}
	/**
	 * @param begin the index of the beginning of the text classified from a document
	 */
	public void setBegin(int begin) {
		this.begin = begin;
	}
	/**
	 * @return the index of the ending of the text classified from a document
	 */
	public int getEnd() {
		return end;
	}
	/**
	 * @param end the index of the ending of the text classified from a document
	 */
	public void setEnd(int end) {
		this.end = end;
	}
	/**
	 * @return the specific type of the annotation, as in a keyword mapping to the actual 
	 * class name, according to the file <code>config/type_mappings.config</code>
	 */
	public String getType() {
		return type;
	}
	/**
	 * @param type the specific type of the annotation, as in a keyword mapping to the actual 
	 * class name, according to the file <code>config/type_mappings.config</code>
	 */
	public void setType(String type) {
		this.type = type;
	}
	/**
	 * @return the text covered by an annotation as a string
	 */
	public String getCoveredText() {
		return coveredText;
	}
	/**
	 * @param coveredText the text covered by an annotation as a string
	 */
	public void setCoveredText(String coveredText) {
		this.coveredText = coveredText;
	}
	/**
	 * @return the list of Objects identifying this particular annotation
	 */
	public List<Object> getDistinguisher() {
		return distinguisher;
	}
	/**
	 * @param distinguisher the list of Objects identifying this particular annotation
	 */
	public void setDistinguisher(List<Object> distinguisher) {
		this.distinguisher = distinguisher;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof MyAnnotation))
			return false;
		MyAnnotation annot = (MyAnnotation) obj;
		if (annot.getType().equals(getType())
				&& annot.getBegin() == getBegin()
				&& annot.getEnd() == getEnd()
				&& annot.getCoveredText().equals(getCoveredText())
				&& annot.getDistinguisher().equals(getDistinguisher())
				&& annot.hashCode() == hashCode())
			return true;
		
		return false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return getBegin()
				+ 31 * getEnd()
				+ 31 * 31 * getType().hashCode()
				+ 31 * 31 * 31 * getCoveredText().hashCode()
				+ 31 * 31 * 31 * 31	* getDistinguisher().hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}
	
	
	
}
